<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>会员注册_中国根雕行业网</title>
     <link rel="shortcut icon" href="../favicon.ico" type="image/x-icon">
    <link href="../css/regist.css" type="text/css" rel="stylesheet">
    <link href="../css/style.css" type="text/css" rel="stylesheet">
</head>
<body>

<!--头部-->
<div class="top">
    <div class="top_box">
        <div class="top_box_left">
            <div class="black fw_b fs_12">欢迎光临中国根雕行业网</div>
        </div>
    </div>
</div>

<div class="content">
    <div class="content_top">
        <div class="logo" align="center">
            <img src="../img/logo.png" alt="中国根雕行业网">
        </div>

        <div class="tittle">
            会员注册
        </div>
    </div>
</div>

<div class="line">
</div>


<div class="information bor">
    <img src="../regist/re1.jpg" alt="完善信息资料">

    <div class="info_box">
        <h3>信息资料</h3>
        <div class="info">
            <div class="info_left">
                <span class="info_tit">用户性别</span>
            </div>
            <div class="info_right">
                <input type="radio" name="sex" id="per" checked="checked" value="1"><label for="per" >男</label>&nbsp;&nbsp;&nbsp;&nbsp;
                <input type="radio" name="sex" id="com" value="0"><label for="com" >女</label>
            </div>
        </div>
        <div class="info">
            <div class="info_left">
                <span class="info_tit">用户姓名</span>
            </div>
            <div class="info_right">
                <input type="text" class="info_in" id="trueName" onblur="checkName()">
            </div>
        </div>
        <div class="info">
            <div class="info_left">
                <span class="info_tit">手机号码</span>
            </div>
            <div class="info_right">
                <input type="text" class="info_in" id="tel" onblur="checkTel()">
            </div>
        </div>
        <div class="info">
            <div class="info_left">
                <span class="info_tit">用户地址</span>
            </div>
            <div class="info_right">
                <input type="text" class="info_in" id="address" onblur="checkAddress()">
            </div>
        </div>
        <div class="info">
            <div class="info_left">
                <span class="info_tit">预留问题</span>
            </div>
            <div class="info_right">
                <select id="question">
                    <option>您的出生地？</option>
                    <option>您最喜欢的作品？</option>
                    <option>您父亲的姓名？</option>
                    <option>您母亲的姓名？</option>
                    <option>您配偶的姓名？</option>
                </select>
            </div>
        </div>
        <div class="info">
            <div class="info_left">
                <span class="info_tit">预留问题答案</span>
            </div>
            <div class="info_right">
                <input type="text" class="info_in" id="answer" onblur="checkAnswer()">
            </div>
        </div>
        <div class="bu white" onclick="submit()">确认提交</div>
    </div>

</div>


<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript">

	var se=decodeURIComponent(window.location.search).substring(1);
	var userType=se.split("&")[0];
	var userNo=se.split("&")[1];
	var email=se.split("&")[2];
	var loginPassword=se.split("&")[3];

    var sexVal;
    var trueName;
    var tel;
    var address;
    var question;
    var answer;
    //用户姓名正则
    var de_name = /^[\u4e00-\u9fa5]{0,}$/;
    //    电话正则
    var de_tel= /^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/;
    //    检验用户名
    function checkName() {
        trueName = $.trim($("#trueName").val());
        if (trueName == "" || de_name.test(trueName) == false || trueName.length< 2 ||trueName.length > 4) {
            alert("请填写真实的姓名");
            return 2;
        } else {
            return 1;
        }
    }
    //   检验电话
    function checkTel() {
        tel = $.trim($("#tel").val());
        if (tel!=""&&de_tel.test(tel) == false) {
            alert("请填写正确的手机号码");
            return 2;
        }else{
            return 1;
        }
    }
    //    检验地址
    function checkAddress(){
        address = $.trim($("#address").val());
        if (address == "") {
            alert("请填写地址");
            return 2;
        }else{
            return 1;
        }
    }
    //    检验答案
    function checkAnswer(){
        answer = $.trim($("#answer").val());
        if (answer == "") {
            alert("请输入预留问题答案");
            return 2;
        }else{
            return 1;
        }
    }


    function submit() {
        sexVal = $('input:radio[name="sex"]:checked').val();
        trueName = $.trim($("#trueName").val());
        tel = $.trim($("#tel").val());
        address = $.trim($("#address").val());
        question = $.trim($("#question").val());
        answer = $.trim($("#answer").val());
        if (trueName == "" || tel == "" || address == "" || answer == "") {
            alert("请完善所有信息")
        }else if(checkTel()+checkName()+checkAddress()+checkAnswer()!=4){
            alert("信息有误，请核对确认")
        }else{
        	  $.ajax({
                  type:"POST",
                  url:"<%=basePath%>User/regist",
                  dataType:"json",
                  data:'registryParam='+'{userInfo:{userType:'+userType+',userNo:'+userNo+',email:'+email+',loginPassword:'+loginPassword+',safeQuestion:'+question+',answer:'+answer+',userName:'+trueName+',address:'+address+',phoneNo:'+tel+',sex:'+sexVal+'},userType:'+userType+'}',
                  success:function(result){
                      if(result.code=="1"){
                      	 window.location.href="success.jsp?"+encodeURIComponent(userNo);
                      }else{         
                     alert("注册失败");
                      }
                  }
                  ,
                  error: function() {
                      alert("error");
                    }
            
              });
        }
    }
</script>


</body>
</html>